﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CLIGenProto
{
    public partial class CLIGenMain : Form
    {
        string activecli = "";
        string ActiveCLI
        {
            get { return activecli; }
            set
            {
                activecli = value;
            }
        }
        string activecom = "";
        string ActiveCommand
        {
            get { return activecom; }
            set
            {
                activecom = value;
            }
        }
        string activeparam = "";
        string ActiveParameter
        {
            get { return activeparam; }
            set
            {
                activeparam = value;
            }
        }

        Dictionary<string, Dictionary<string, List<string>>> CLIs = new Dictionary<string, Dictionary<string, List<string>>>();

        bool CreateCLI(string name)
        {
            if (!CLIs.ContainsKey(name))
                CLIs.Add(name, new Dictionary<string, List<string>>());
            else
                return false;
            return true;
        }

        bool DeleteCLI(string name)
        {
            if (CLIs.ContainsKey(name))
                CLIs.Remove(name);
            else
                return false;
            return true;
        }

        public CLIGenMain()
        {
            InitializeComponent();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void EnvironmentTree_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F2)
                EnvironmentTree.SelectedNode.BeginEdit();
        }

        private void EnvironmentTree_MouseUp(object sender, MouseEventArgs e)
        {
            Point clickPoint = new Point(e.X, e.Y);
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                TreeNode clicked = EnvironmentTree.GetNodeAt(clickPoint);
                if (clicked == null)
                {
                    TreeViewContextMenu.Items[0].Visible = true;
                    TreeViewContextMenu.Items[1].Visible = false;
                    TreeViewContextMenu.Items[2].Visible = false;
                }
                else if (clicked.Level != 0)
                {
                    TreeViewContextMenu.Items[0].Visible = false;
                    TreeViewContextMenu.Items[1].Visible = true;
                    TreeViewContextMenu.Items[2].Visible = true;
                }
                else
                {
                    TreeViewContextMenu.Items[0].Visible = true;
                    TreeViewContextMenu.Items[1].Visible = true;
                    TreeViewContextMenu.Items[2].Visible = true;
                }
                EnvironmentTree.SelectedNode = clicked;
                TreeViewContextMenu.Show(EnvironmentTree, clickPoint);
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            if (textBox2.Text.Length > 1)
                textBox2.Text = textBox2.Text.Remove(1);
        }
    }
}
